package com.qf.service.impl;

import com.qf.dao.HealthDao;
import com.qf.dao.impl.HealthDaoImpl;
import com.qf.entity.Health;
import com.qf.service.HealthService;
import com.qf.util.DruidUtil;
import com.qf.util.Page;

import java.util.List;

/*
杨威
2021/10/5
15:38
*/
public class HealthServiceImpl implements HealthService {
    HealthDao healthDao=new HealthDaoImpl();
    @Override
    public List<Health> showAll(Page page) {
        List<Health> healthList = healthDao.selectAll(page);
        Long count = healthDao.selectCount();
        page.setTotalCount(count);
        DruidUtil.close();
        return healthList;
    }

    @Override
    public int add(Health health) {
        int insert = healthDao.insert(health);
        DruidUtil.close();
        return insert;
    }

    @Override
    public Health showHealth(Integer id) {
        Health select = healthDao.select(id);
        DruidUtil.close();
        return select;
    }

    @Override
    public int updateHealth(Health health) {
        int update = healthDao.update(health);
        DruidUtil.close();
        return update;
    }

    @Override
    public int deleteHealth(Integer id) {
        int delete=0;
        try {
            DruidUtil.begin();
            delete = healthDao.delete(id);

            DruidUtil.commit();
        } catch (Exception e) {
            DruidUtil.rollback();
            e.printStackTrace();
        } finally {
            DruidUtil.close();
        }
        return delete;
    }
}
